package J20250330_real;

/**
 * Created with IntelliJ IDEA.
 * Description: 分布式队列——https://www.lanqiao.cn/paper/4400/problem/19723/
 * User: 王圆豪
 * Date: 2025-04-05
 * Time: 15:05
 */
import java.util.*;
// 1:无需package
// 2: 类名必须Main, 不可修改

public class Main8 {
    static int n;
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        n = scan.nextInt();
        int[] count = new int[n];
        while(scan.hasNext()){
            String s = scan.next();
            if(s.equals("query")){
                int min = Integer.MAX_VALUE;
                for(int i = 0; i < count.length; i++){
                    min = Math.min(count[i],min);
                }
                System.out.println(min);
            }else{
                int x = scan.nextInt();
                if(s.equals("add")){
                    count[0]++;
                }else{
                    count[x] = Math.min(count[x]+1,count[0]);
                }
            }
        }
        scan.close();
    }
}